package com.smile.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.GenerateAirlineFileRequestDTO;
import com.smile.model.dto.request.GeneratePlanarAirlineRequestDTO;
import com.smile.model.request.GenerateAirlineFileRequest;
import com.smile.model.request.GeneratePlanarAirlineRequest;
import com.smile.model.response.GenerateAirlineFileResponse;
import com.smile.model.response.response.GenerateAirlineFileResponseDTO;
import com.smile.service.FlightTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;


@RestController
@RequestMapping("/flightTask")
public class FlightTaskController {

    @Autowired
    private FlightTaskService flightTaskService;


    @SaIgnore
    @PostMapping("/generateAirlineFile")
    public R<GenerateAirlineFileResponse> generateAirlineFile(@RequestBody GenerateAirlineFileRequest generateAirlineFileRequest) throws IOException {
        GenerateAirlineFileRequestDTO generateAirlineFileRequestDTO = BeanUtil.copyProperties(generateAirlineFileRequest, GenerateAirlineFileRequestDTO.class);
        GenerateAirlineFileResponseDTO generateAirlineFileResponseDTO = flightTaskService.generateAirlineFile(generateAirlineFileRequestDTO);

        return R.ok(BeanUtil.copyProperties(generateAirlineFileResponseDTO, GenerateAirlineFileResponse.class));
    }

    @SaIgnore
    @PostMapping("/generatePlanarAirline")
    public R<GenerateAirlineFileResponse> generatePlanarAirline(@RequestBody GeneratePlanarAirlineRequest generatePlanarAirlineRequest) throws IOException {
        GenerateAirlineFileResponseDTO generateAirlineFileResponseDTO = flightTaskService.generatePlanarAirline(BeanUtil.copyProperties(generatePlanarAirlineRequest, GeneratePlanarAirlineRequestDTO.class));
        return R.ok(BeanUtil.copyProperties(generateAirlineFileResponseDTO, GenerateAirlineFileResponse.class));
    }


}
